using UnityEngine;
using System.Collections;

public class Map : MonoBehaviour {
	public Transform FloorP;
	public Transform WallP;
	public GameObject Player;
	//private ArrayList lol = new ArrayList();
	//private Waypoint [,] _arrWaypoints = new Waypoint [1000,1000];
	//private Queue _tempQueue = new Queue();
	private Hashtable _wpHashTable = new Hashtable();
	
	public void GenMap(){
		Player.transform.position = new Vector3(0,0.58f,0);
		//floorWaypoints(0,0);
		room(10,10,0,0);
	}
	public Queue PathToCoor(float goalX, float goalY, float startX, float startY){
		Queue tempQueue = new Queue();
		nearestWP(goalX,goalY);
		return tempQueue;
	}
	private Waypoint nearestWP(float x, float y){
		float tempX = (x-0.125f)%0.125f;
		float tempY = (y-0.125f)%0.125f;
		if(Mathf.Abs(tempX)<Mathf.Abs(tempY)){
			
		}
		//print("x = " + x + ", nearest shit = " + (Mathf.Round((x-0.125f)/0.25f)*0.25f+0.125f));
		//print(tempX + "," + tempY);
		return new Waypoint(0,0);
	}
	private void room(int w, int h, int x, int y){
		for(int i = 0; i <= w-1; i++){
			Transform fucks = Instantiate(WallP, new Vector3(x-1,0,i+y), Quaternion.AngleAxis(0, Vector3.up)) as Transform;
			Transform lol = Instantiate(WallP, new Vector3(i+x,0,y-1), Quaternion.AngleAxis(270, Vector3.up)) as Transform;
			Transform fucksss = Instantiate(WallP, new Vector3(x+w,0,y+h-i-1), Quaternion.AngleAxis(180, Vector3.up)) as Transform;
			Transform fuck = Instantiate(WallP, new Vector3(x+w-i-1,0,y+h), Quaternion.AngleAxis(90, Vector3.up)) as Transform;
			for(int d = 0; d <= h-1; d++){
				Transform blah = Instantiate(FloorP, new Vector3(i+x,0,d+y), Quaternion.identity) as Transform;
				floorWaypoints(i+x, d+y);
			}
		}
	}
	private void floorWaypoints(int x, int y){
		for(int i = 1; i <= 4; i++){
			for(int d = 1; d <= 4; d++){
				float newX = (float)(x+((i*0.25)-0.625));
				float newY = (float)(y+((d*0.25)-0.625));
				//print(((i*0.25)-0.625) + " , " + ((d*0.25)-0.625));
				//float temp = (float)(x+((i*0.25)-0.625));
				//Waypoint temp = new Waypoint(new float(x+((i*0.25)-0.625)), y+((d*0.25)-0.625));
				_wpHashTable.Add(""+newX+","+newY, new Waypoint(newX,newY));
			}
		}
	}
}